﻿#region

using System.IO;
using System.Reflection;
using MediaSage.Lib.Configuration;
using MediaSage.Lib.Database;
using MediaSage.Lib.Plugin;
using MediaSage.Lib.Utilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#endregion

namespace MediaSageLibTest
{
    /// <summary>
    ///     Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class ConfigTest
    {
        #region Fields

        public static Config config;
        public static PluginBase provider;

        #endregion Fields

        #region Constructors

        #endregion Constructors

        #region Properties

        ///<summary>
        ///    Gets or sets the test context which provides
        ///    information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext { get; set; }

        #endregion Properties

        #region Methods

        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        [ClassInitialize]
        public static void LoadConfiguration(TestContext testContext)
        {
            config = new Config();
        }

        [TestMethod]
        public void CheckVersion()
        {
            var PE = new PluginEntity();
            PE.Location = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                                       "IMDBProvider.dll");
            provider = Plugin.LoadPlugin(config, PE);
            VersionInfo vi = provider.GetVersionInfo();
            Assert.AreEqual(0, vi.MajorVersion, "Major version != 0");
            Assert.AreEqual(9, vi.MinorVersion, "Minor version != 9");
            Assert.AreEqual("IMDBProvider", vi.Name, "Name of provider != IMDBProvider");
        }

        [TestMethod]
        public void LoadProviderPlugin()
        {
            var PE = new PluginEntity();
            PE.Location = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                                       "FileNameProvider.dll");
            provider = Plugin.LoadPlugin(config, PE);
            if (provider == null)
            {
                Assert.Fail("provider==null");
            }
        }

        [TestMethod]
        public void TestLoadConfiguration()
        {
            if (config == null)
            {
                Assert.Fail("Configuration == null");
            }
        }

        #endregion Methods
    }
}